﻿using TagChimp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection;
using System.Threading.Tasks;

namespace TagChimp.Tests
{
    
    
    /// <summary>
    ///This is a test class for TagChimpClientTest and is intended
    ///to contain all TagChimpClientTest Unit Tests
    ///</summary>
    [TestClass()]
    [DeploymentItem("TagChimp.dll")]
    public class TagChimpClientTest
    {

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }
        private TagChimpClient_Accessor target = new TagChimpClient_Accessor("5952710984D89ACECA4C82");
        
        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion





        [TestMethod()]
        public void BuildQueryUrlReturnsValidTagChimpQueryUrlForEpisodeInfo()
        {
            
            
            //arrange 
            var ei = new EpisodeInfo("Fringe", 2, 3);
            const string expected = "http://tagchimp.com/ape/lookup.php?token=5952710984D89ACECA4C82&show=Fringe&season=2&episode=3&limit=1"; ;
            string actual;
            
            //act
            actual = target.BuildQueryUrl(ei);
          
            
            //assert
            
            Assert.AreEqual(expected, actual);
           
        }
        [TestMethod]
        public void BuildQueryUrlReturnsValidTagChimpQueryUrlForMovieInfo()
        {
            //arrange
             
            var mi = new MovieInfo("Tron", 1984);
            const string expected = "http://tagchimp.com/ape/lookup.php?token=5952710984D89ACECA4C82&type=search&title=Tron&totalChapters=X&locked=IsLocked&videoKind=Movie";
            
            //act
            string actual = target.BuildQueryUrl(mi);
            
            //assert

            Assert.AreEqual(expected, actual);
        }
        [TestMethod]
        public void GetMovieInfoReturnsPopulatedMovieInfoWithFilename()
        {
            //arrange
            MovieInfo mi;
            //act
            mi = target.getMovieInfo("The Eagle 2011 R5 READNFO XViD - IMAGiNE");
            //assert
            Type type = mi.GetType();
            PropertyInfo[] props = type.GetProperties();


            var t = Task.Factory.StartNew(() => Array.ForEach(props, p =>
            {
                object val = p.GetValue(mi, null);
                if (val is string && String.IsNullOrEmpty((string)val))
                    Assert.Fail(p.Name + " returned null or empty");
                if (val is int && (int)val <= 0)
                    Assert.Fail(p.Name + " returned null or empty");
            }));
            t.Wait();
        }
        





    }
}
